///***********************************************************************
/// GoalStatusBase.cs
/// Owner: joemu
///
/// Provides a .NET Wrapper around the Stored Procedures in the
/// Lazarus database.
///
/// Copyright(c) Microsoft Corporation
///***********************************************************************

using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

using OR.Reuse.Persistence;

using OR.MyGoals.DataAccess;
	   
namespace OR.MyGoals.DataAccess.Generated
{
   /// <summary>
   /// Specifies a technology for which you are tracking competency.
   /// </summary>
   public class GoalStatusBase : DataAccessBase
   {
      #region Private Property Fields
      
      #endregion
      
      #region Constructors
      
      /// <summary>
	  /// Constructs a new Goal Status and initializes a new SqlConnection.
      /// </summary>
      public GoalStatusBase() : base()
      {
      }
      
      /// <summary>
      /// Constructs a new Goal Status initialized with the specified SqlConnection.
      /// </summary>
      public GoalStatusBase( SqlConnection existingConnection) : base( existingConnection )
      {
      
      }
      
      #endregion
      
      #region Public Methods

      
      /// <summary>
      /// Creates a new Goal Status.
      /// </summary>
      /// <param name="id"></param>
      /// <param name="title"></param>
      /// <param name="description"></param>
      /// <param name="created"></param>
      /// <param name="modified"></param>
      public void Create
      (
         out System.Int32 id,
         string title,
         string description,
         out System.DateTime created,
         System.DateTime modified
      )
      {
         
         SqlCommand  currentCommand      = new SqlCommand();
         
         currentCommand.CommandType      = CommandType.StoredProcedure;
         currentCommand.CommandText      = "[spGoalStatusCreate]";
         currentCommand.Connection       = this.Connection;
   

         currentCommand.Parameters.Add( new SqlParameter( "@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null ) );
         currentCommand.Parameters.Add( new SqlParameter( "@id", SqlDbType.Int, 4 ) );
         
				currentCommand.Parameters[ "@id" ].Direction = ParameterDirection.Output;
            if ( String.IsNullOrEmpty( title ) )
         {
            currentCommand.Parameters.Add( new SqlParameter( "@title", SqlDbType.VarChar, 50 ) ).Value = DBNull.Value;
         }
         else
         {
            currentCommand.Parameters.Add( new SqlParameter( "@title", SqlDbType.VarChar, 50 ) ).Value = title;
            }

            if ( String.IsNullOrEmpty( description ) )
         {
            currentCommand.Parameters.Add( new SqlParameter( "@description", SqlDbType.Text ) ).Value = DBNull.Value;
         }
         else
         {
            currentCommand.Parameters.Add( new SqlParameter( "@description", SqlDbType.Text ) ).Value = description;
            }

            currentCommand.Parameters.Add( new SqlParameter( "@created", SqlDbType.DateTime, 1 ) );
         
				currentCommand.Parameters[ "@created" ].Direction = ParameterDirection.Output;
            currentCommand.Parameters.Add( new SqlParameter( "@modified", SqlDbType.DateTime, 1 ) ).Value = modified;
         
      
	     if ( Connection.State != ConnectionState.Open ) { Connection.Open(); }
         
         currentCommand.ExecuteNonQuery();
         
         // Dump out the output params.
         id = ( System.Int32 )currentCommand.Parameters[ "@id" ].Value;created = ( System.DateTime )currentCommand.Parameters[ "@created" ].Value;
      
	     if ( !this.MaintainConnection ) { this.Connection.Close(); }
      }
   
      /// <summary>
      /// Updates an existing Goal Status matching the specified ID.
      /// </summary>
      /// <param name="id"></param>
      /// <param name="title"></param>
      /// <param name="description"></param>
      /// <param name="modified"></param>
      public void Update
      (
         System.Int32 id,
         string title,
         string description,
         System.DateTime modified
      )
      {
         
         SqlCommand  currentCommand      = new SqlCommand();
         
         currentCommand.CommandType      = CommandType.StoredProcedure;
         currentCommand.CommandText      = "[spGoalStatusUpdate]";
         currentCommand.Connection       = this.Connection;
   

         currentCommand.Parameters.Add( new SqlParameter( "@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null ) );
         currentCommand.Parameters.Add( new SqlParameter( "@id", SqlDbType.Int, 4 ) ).Value = id;
         if ( String.IsNullOrEmpty( title ) )
         {
            currentCommand.Parameters.Add( new SqlParameter( "@title", SqlDbType.VarChar, 50 ) ).Value = DBNull.Value;
         }
         else
         {
            currentCommand.Parameters.Add( new SqlParameter( "@title", SqlDbType.VarChar, 50 ) ).Value = title;
            }

            if ( String.IsNullOrEmpty( description ) )
         {
            currentCommand.Parameters.Add( new SqlParameter( "@description", SqlDbType.Text ) ).Value = DBNull.Value;
         }
         else
         {
            currentCommand.Parameters.Add( new SqlParameter( "@description", SqlDbType.Text ) ).Value = description;
            }

            currentCommand.Parameters.Add( new SqlParameter( "@modified", SqlDbType.DateTime, 1 ) ).Value = modified;
         
      
	     if ( Connection.State != ConnectionState.Open ) { Connection.Open(); }
         
         currentCommand.ExecuteNonQuery();
         
         // Dump out the output params.
         
      
	     if ( !this.MaintainConnection ) { this.Connection.Close(); }
      }
   
      /// <summary>
	  /// Returns a single Goal Status matching the specified ID.
	  /// </summary>
      /// <param name="id"></param>
      /// <returns>DataSet containing matching records.</returns>
      public override DataSet Get
      (
         System.Int32 id
      )
      {
         try
         {
				
         SqlCommand  currentCommand      = new SqlCommand();
         
         currentCommand.CommandType      = CommandType.StoredProcedure;
         currentCommand.CommandText      = "[spGoalStatusGet]";
         currentCommand.Connection       = this.Connection;
   

				currentCommand.Parameters.Add( new SqlParameter( "@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null ) );
				currentCommand.Parameters.Add( new SqlParameter( "@id", SqlDbType.Int, 4 ) ).Value = id;
         
      
			if ( this.Connection.State != ConnectionState.Open ) { this.Connection.Open(); }
            
				SqlDataReader resultReader = currentCommand.ExecuteReader();
	         
				// Dump out the output params.
				
            
            DataSet rtnVal = new DataSet();
            rtnVal.Load( resultReader, LoadOption.OverwriteChanges, "GoalStatus" );
            
            resultReader.Close();
            
	     if ( !this.MaintainConnection ) { this.Connection.Close(); }
            
            return( rtnVal );
         }
         catch ( SqlException e )
         {
            throw new Exception ( e.Message ); 
         }         
      }
   
      /// <summary>
	  /// Returns a list of Goal Status records.
	  /// </summary>
      public DataSet List()
      {
         try
         {
				
         SqlCommand  currentCommand      = new SqlCommand();
         
         currentCommand.CommandType      = CommandType.StoredProcedure;
         currentCommand.CommandText      = "[spGoalStatusList]";
         currentCommand.Connection       = this.Connection;
   

				currentCommand.Parameters.Add( new SqlParameter( "@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null ) );
				
      
			if ( this.Connection.State != ConnectionState.Open ) { this.Connection.Open(); }
            
				SqlDataReader resultReader = currentCommand.ExecuteReader();
	         
				// Dump out the output params.
				
            
            DataSet rtnVal = new DataSet();
            rtnVal.Load( resultReader, LoadOption.OverwriteChanges, "GoalStatus" );
            
            resultReader.Close();
            
	     if ( !this.MaintainConnection ) { this.Connection.Close(); }
            
            return( rtnVal );
         }
         catch ( SqlException e )
         {
            throw new Exception ( e.Message ); 
         }         
      }
   

	   public override DataTable EmptyTable()
	   {
	   DataTable rtnVal = new DataTable();

	   rtnVal.TableName = "GoalStatus";
         
         
			 rtnVal.Columns.Add( new DataColumn( "Id", typeof( System.Int32 ) ) );
			 rtnVal.Columns.Add( new DataColumn( "Title", typeof( System.String ) ) );
			 rtnVal.Columns.Add( new DataColumn( "Description", typeof( System.String ) ) );
			 rtnVal.Columns.Add( new DataColumn( "Created", typeof( System.DateTime ) ) );
			 rtnVal.Columns.Add( new DataColumn( "Modified", typeof( System.DateTime ) ) );

	   return( rtnVal );
	   }

	   #endregion
	}
}
   